function bubbleSort(nums) {
    var n = nums.length
    for (var i = 0; i < n - 1; i++) {
        for (var j = 0; j < n - 1 - i; j++) {
            if (nums[j] > nums[j + 1]) {
                var temp = nums[j + 1];
                nums[j + 1] = nums[j];
                nums[j] = temp;
            }
        }

    }
    console.log(nums)
}

function selectionSort(nums) {
    var n = nums.length
    var min_index, temp;
    for (var i = 0; i < n - 1; i++) {
        min_index = i
        for (var j = i + 1; j < n; j++) {
            if (nums[j] < nums[min_index]) {
                min_index = j
            }

        }
        temp = nums[min_index];
        nums[min_index] = nums[i];
        nums[i] = temp;

    }
    console.log(nums)
}

function insertionSort(nums) {
    var len = nums.length
    var pre_index, current
    for (var i = 0; i < len; i++) {
        pre_index = i - 1;
        current = nums[i];
        while (pre_index >= 0 && nums[pre_index] > current) {
            nums[pre_index + 1] = nums[pre_index]
            pre_index--;
        }
        nums[pre_index + 1] = current
    }
    console.log(nums)
}

const nums = [2, 9, 4, 3, 10, 6, 5, 8, 7, 1]
// bubbleSort(nums)
// selectionSort(nums)
insertionSort(nums)